{% extends 'base.html' %}

{% block content %}


<br/>
<ul class="nav nav-tabs">
{% for version in versions %}
  <li class="nav-item">
	  <a class="nav-link {% if loop.index == 1 %}active{% endif %}" data-toggle="tab" href="#release{{ version.id }}">Release {{ version.next_release }} {% if loop.index == 1 %}(devel){% endif %}</a>
  </li>
{% endfor %}
</ul>


<div class="tab-content">
{% for version in versions %}
  <div class="tab-pane {% if loop.index == 1 %}active{% endif %}" id="release{{ version.id }}">
    <br/>
    {% if loop.index != 1 %}
    <table class="table table-bordered">
      <thead>
        <tr>
          <th scope="col">General Availability</th>
          <th scope="col">End of Full Support</th>
          <th scope="col">End of Maintenance Support 1</th>
          <th scope="col">End of Life</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>{{ version.general_availability }}</th>
          <td>{{ version.end_of_full_support }}</td>
          <td>{{ version.end_of_maintenance_support }}</td>
          <td>{{ version.end_of_life }}</td>
        </tr>
      </tbody>
    </table>
    {% endif %}
    {% if loop.index == 1 %}
    <a href="{{ version.spreadsheet_url }}">Tower {{ version.next_release[:3] }} Feature Planning</a> -
    {% endif %}
    <a href="{{ version.project }}">Ansible Project</a> -
    {% if version.next_release_test_plan %}
        <a href="{{ version.next_release_test_plan }}">Test Plan</a>
    {% else %}
        No Test Plan available yet
    {% endif %}
    <br/><br/>

    {% if version.issues %}
    <h4 id="issues">Issues (<a href="{{ version.issues.html_url}}">{{ version.issues.count }}</a> open | <a href="{{ version.issues.needs_test_html_url }}">{{ version.issues.needs_test_count }}</a> in needs_test)</h4>
    {% else %}
    <h4>Issues</h4>
    {% endif %}
    <hr/>

    {% if not version.issues %}
    No issue marked with the <b>release_{{ version.next_release }}</b> milestone
    {% elif version.issues.needs_test_count > 0 %}
<div id="accordionIssues">
  <div class="card">
    <div class="card-header" id="headingIssues">
      <h5 class="mb-0">
        <button class="btn btn-link" data-toggle="collapse" data-target="#collapseIssues" aria-expanded="true" aria-controls="collapseIssues">
         Click to expand or hide the list of issues in with label <i>state:needs_test</i></br></br>
        </button>
      </h5>
    </div>

    <div id="collapseIssues" class="collapse show" aria-labelledby="headingIssues" data-parent="#accordionIssues">
      <div class="card-body">
        <img src="{{ url_for('static', filename='yellow_rectangle.png') }}" style="height: 30px; width: 30px"></img> No QE assigned
        <img src="{{ url_for('static', filename='grey_rectangle.png') }}" style="height: 30px; width: 30px"></img> Nobody assigned</br></br>
        <table class="table table-bordered" style="border-collapse: collapse">
          <thead>
            <tr style="border-bottom: double">
              <th style="vertical-align: middle">Issue</th>
              <th style="vertical-align: middle">Assignee</th>
              <th style="vertical-align: middle">Last Updated</th>
            </tr>
          </thead>
          <tbody>
            {% for issue in version.issues.needs_test_issues %}
            <tr style="{{ 'background-color: #DCDCDC' if issue.assignee == '' else ('background-color: #ffffbb' if issue.qe_or_not==False else '') }}">
                <td><a href="{{ issue.url }}">{{ issue.title }}</a></td>
                <td>{{ issue.assignee if issue.assignee != '' else 'Nobody yet' }}</td>
                <td>{{ issue.updated_at }}</td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
    {% else %}
    No issue labeled with <i>label:state:needs_test</i> for this milestone
    {% endif %}
    <br/><br/>
    <h4 id="integration_results">Integration Results</h4>
    <hr/>

    <img src="{{ url_for('static', filename='green.png') }}"></img><img src="{{ url_for('static', filename='red.png') }}"></img><img src="{{ url_for('static', filename='yellow.png') }}"></img> Fresh results (Less than 2 days)
    <img style="opacity: 0.5;" src="{{ url_for('static', filename='green.png') }}"></img><img style="opacity: 0.5;" src="{{ url_for('static', filename='red.png') }}"></img><img style="opacity: 0.5;" src="{{ url_for('static', filename='yellow.png') }}"></img> Non fresh results (older than 2 days)
    <img src="{{ url_for('static', filename='grey.png') }}"></img> Never run yet
    <br/><br/>

    <table class="table">
      <thead align="center">
        <tr>
          <th scope="col">Status</th>
          <th scope="col">Meaning</th>
        </tr>
      </thead>
      <tbody align="center">
        <tr>
          <td style="text-align: center">
            <img src="{{ url_for('static', filename='green.png') }}"></img>
          </td>
          <td style="text-align: center">
            No failures or regressions - Ready to ship it.
          </td>
        </tr>
        <tr>
          <td style="text-align: center">
            <img src="{{ url_for('static', filename='yellow.png') }}"></img>
          </td>
          <td style="text-align: center">
            Almost there - A few failures or regressions. Needs some attention.
          </td>
        </tr>
        <tr>
          <td style="text-align: center">
            <img src="{{ url_for('static', filename='red.png') }}"></img>
          </td>
          <td style="text-align: center">
            Possibly an infra issue. Needs some attention.
          </td>
        </tr>
      </tbody>
    </table>

    <br/><br/>
    {% for result in misc_results %}
    {% if result.id == version.id %}
    <b>{{ result.os_description }}:</b>
              {% if result.status == 'SUCCESS' %}
                {% if result.freshness < 2 %}
                <td style="text-align: center"><a href="{{ result.url }}"><img src="{{ url_for('static', filename='green.png') }}"></img></a></td>
                {% else %}
                <td style="text-align: center"><a href="{{ result.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='green.png') }}"></img></a></td>
                {% endif %}
              {% elif result.status == 'FAILURE' %}
                {% if result.freshness < 2 %}
                <td style="text-align: center"><a href="{{ result.url }}"><img src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                {% else %}
                <td style="text-align: center"><a href="{{ result.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                {% endif %}
              {% elif result.status == 'UNSTABLE' %}
                {% if result.freshness < 2 %}
                <td style="text-align: center"><a href="{{ result.url }}"><img src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                {% else %}
                <td style="text-align: center"><a href="{{ result.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                {% endif %}
              {% else %}
                <td style="text-align: center">
                {% if result.url %}
                    <a href="{{ result.url }}"><img src="{{ url_for('static', filename='grey.png') }}"></img></a>
                {% else %}
                    <img src="{{ url_for('static', filename='grey.png') }}"></img>
                {% endif %}
                </td>
              {% endif %}
    {% endif %}
    {% endfor %}
    <br/><br/>

    <table class="table table-bordered">
        <thead align="center">
          <th scope="col"></th>
          <th scope="col">devel</th>
          <th scope="col">stable-2.9</th>
          <th scope="col">stable-2.8</th>
          <th scope="col">stable-2.7</th>
        </thead>
        <tbody>
            {% for result in results %}
            {% if result.id == version.id %}

              {% if loop.index == 1 or result.ansible == 'devel'%}
              <tr>
              <th scope="row">{{ result.os_description }}</th>
              {% endif %}

              {% if result.status == 'SUCCESS' %}
                {% if result.freshness < 2 %}
                <td style="text-align: center"><a href="{{ result.url }}"><img src="{{ url_for('static', filename='green.png') }}"></img></a></td>
                {% else %}
                <td style="text-align: center"><a href="{{ result.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='green.png') }}"></img></a></td>
                {% endif %}
              {% elif result.status == 'FAILURE' %}
                {% if result.freshness < 2 %}
                <td style="text-align: center"><a href="{{ result.url }}"><img src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                {% else %}
                <td style="text-align: center"><a href="{{ result.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                {% endif %}
              {% elif result.status == 'UNSTABLE' %}
                {% if result.freshness < 2 %}
                <td style="text-align: center"><a href="{{ result.url }}"><img src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                {% else %}
                <td style="text-align: center"><a href="{{ result.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                {% endif %}
              {% else %}
                <td style="text-align: center">
                {% if result.url %}
                    <a href="{{ result.url }}"><img src="{{ url_for('static', filename='grey.png') }}"></img></a>
                {% else %}
                    <img src="{{ url_for('static', filename='grey.png') }}"></img>
                {% endif %}
                </td>
              {% endif %}

              {% if result.ansible == 'stable-2.3' and not loop.last %}
              </tr>
              {% endif %}


            {% endif %}
            {% endfor %}
            </tr>
        </tbody>
    </table>
    <br/><br/>
    <h4 id="all_jobs">Unstable Jobs</h4>
    <hr/>
    {% set version_unstable_jobs = [] %}
    {% for job in unstable_jobs %}
      {% if job.tower_id == version.id %}
        {% set version_unstable_jobs = version_unstable_jobs.append(job) %}
      {% endif %}
    {% endfor %}

    {% if version_unstable_jobs %}
    <br/><br/>
    <table class="table table-bordered">
        <thead align="center">
          <th scope="col">Job Name</th>
          <th scope="col">Result</th>
        </thead>
        <tbody>
            {% for job in version_unstable_jobs %}
              <tr>
                <td align="left">{{ job.display_name }}</td>
                <td style="text-align: center"><a href="{{ job.url }}"><img src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                </td>
              </tr>
            {% endfor %}
        </tbody>
    </table>
    {% else %}
    <h5>There are no unstable jobs to display.</h5>
    {% endif %}

    <br/><br/>
    <h4>Failed Jobs</h4>
    <hr/>
    {% set version_failed_jobs = [] %}
    {% for job in failed_jobs %}
      {% if job.tower_id == version.id %}
        {% set version_failed_jobs = version_failed_jobs.append(job) %}
      {% endif %}
    {% endfor %}
    {% if version_failed_jobs %}
    <br/><br/>
    <table class="table table-bordered">
        <thead align="center">
          <th scope="col">Job Name</th>
          <th scope="col">Result</th>
        </thead>
        <tbody>
            {% for job in version_failed_jobs %}
              <tr>
                <td align="left">{{ job.display_name }}</td>
                 <td style="text-align: center"><a href="{{ job.url }}"><img src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                </td>
              </tr>
            {% endfor %}
        </tbody>
    </table>
    {% else %}
    <h5>There are no failed jobs to display.</h5>
    {% endif %}
    <br/><br/>

<div id="accordionSignOff">
  <div class="card">
    <div class="card-header" id="headingSignOff">
      <h5 class="mb-0">
        <h4>All Sign Off Jobs for Release</h4>
        
      </h5>
    </div>

    {% if sign_off_jobs %}
    <button class="btn btn-link" data-toggle="collapse" data-target="#collapseSignOff" aria-expanded="true" aria-controls="collapseSignOff">
      click to hide or expand
    </button>
    <div id="collapseSignOff" class="collapse show" aria-labelledby="headingSignOff" data-parent="#accordionSignOff">
      <div class="card-body">
        <table class="table table-bordered">
            <thead align="center">
              <th scope="col">Job Name</th>
              <th scope="col">Result</th>
            </thead>
            <tbody>
                {% for job in sign_off_jobs %}
                  {% if job.tower_id == version.id %}
                    <tr>
                      <td align="left">{{ job.display_name }}</td>
                      {% if job.status == 'SUCCESS' %}
                        {% if job.freshness < 2 %}
                        <td style="text-align: center"><a href="{{ job.url }}"><img src="{{ url_for('static', filename='green.png') }}"></img></a></td>
                        {% else %}
                        <td style="text-align: center"><a href="{{ job.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='green.png') }}"></img></a></td>
                        {% endif %}
                      {% elif job.status == 'FAILURE' %}
                        {% if job.freshness < 2 %}
                        <td style="text-align: center"><a href="{{ job.url }}"><img src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                        {% else %}
                        <td style="text-align: center"><a href="{{ job.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='red.png') }}"></img></a></td>
                        {% endif %}
                      {% elif job.status == 'UNSTABLE' %}
                        {% if job.freshness < 2 %}
                        <td style="text-align: center"><a href="{{ job.url }}"><img src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                        {% else %}
                        <td style="text-align: center"><a href="{{ job.url }}"><img style="opacity: 0.5" src="{{ url_for('static', filename='yellow.png') }}"></img></a></td>
                        {% endif %}
                      {% else %}
                        <td style="text-align: center">
                        {% if job.url %}
                            <a href="{{ job.url }}"><img src="{{ url_for('static', filename='grey.png') }}"></img></a>
                        {% else %}
                            <img src="{{ url_for('static', filename='grey.png') }}"></img>
                        {% endif %}
                        </td>
                      {% endif %}
                    </tr>
                  {% endif %}
                {% endfor %}
            </tbody>
        </table>
      </div>
    </div>
    {% else %}
    <h5>There are no sign off jobs to display.</h5>
    {% endif %}    
  </div>
</div>

<br/><br/>

  </div>
{% endfor %}
</div>

{% endblock %}
